<?php

declare(strict_types=1);

namespace App\Overwrites;

use Mine\MineCollection;
use Mine\MineResponse;
use Psr\Http\Message\ResponseInterface;

abstract class AbstractService extends \Mine\Abstracts\AbstractService
{
    public function export(
        array $params,
        ?string $dto,
        string $filename = null,
        \Closure $callbackData = null
    ): ResponseInterface {
        if (empty($dto)) {
            return container()->get(MineResponse::class)->error('导出未指定DTO');
        }

        if (empty($filename)) {
            $filename = $this->mapper->getModel()->getTable();
        }

        return (new MineCollection())->export($dto, $filename, $this->mapper->getExportList($params), $callbackData);
    }
}
